$(function () {
    //初始化专业
    $.initSubject({
        element:'lore-subject-box',//初始化专业select元素的ID
        context:'lore-subject-context',//显示专业/科目名字内容ID
        initData:$('#subjectIds').val(),//初始化显示的专业数据，默认不设置
        removeCallback:function(parentId,subjectIds){//删除回调
            resetSubjectIds()
        },
        confirmCallback:function(parentId,subjectIds){//点击确认回调
            resetSubjectIds()
        }
    });
    /**
     * 重置专业ID串
     */
    function resetSubjectIds() {
        var _subjectIds = $.getAllSubjectIds("lore-subject-context");
        $("input[name=subjectIds]").val(_subjectIds);
    }

    //保存第一步后,继续第二步
    $("body").on("click","#save-continue,#back_next",function () {
        saveLore(true);
    });

    //保存第一步后,返回
    $("body").on("click","#save-back",function () {
        saveLore(false);
    });
    //执行保存知识体系数据
    function saveLore(flag) {
        var params = $("#loreset-form").serializeJSON();
        params = JSON.stringify(params);
        $.ajax({
            url: baseloaction + "/admin/manage/loreset/saveLoreset",
            data: params,
            type:"post",
            dataType:"json",
            contentType:'application/json;charset=utf-8',
            success:function (result) {
                if(result.success){
                    if(flag){
                        window.location.href= baseloaction + "/admin/manage/point/toLoresetPointView?loresetId=" + result.entity.id;
                    }else{
                        window.location.href= baseloaction + "/admin/manage/loreset/queryLoresetListPage";
                    }
                }else {
                    icModale(0,result.message);
                }
            },
            error:function (error) {
                icModale(0,"系统繁忙,请稍后重试");
            }
        })
    }
});

